package cc.lucien.singleton;

/**
 * @author lucien-ma
 * @date 2021/10/29
 * @apiNote 单例模式，双重检查
 * volatile 关键字使变量对线程可见
 */
public class Single {
    private volatile static Single instance;

    private Single(){
        System.out.println("创建了Single对象");
    }

    public static Single getInstance() {
        if (instance == null) {
            synchronized (Single.class) {
                if (instance == null) {
                    instance = new Single();
                }
            }
        }
        return instance;
    }

}
